package org.uoss.applications.framework.dao.nativeSQL.impl;

import java.util.Collection;

import org.springframework.orm.jpa.vendor.Database;
import org.uoss.applications.framework.dao.nativeSQL.NativeSQLDAO;
import org.uoss.applications.framework.entity.GeneralObject;
import org.uoss.core.exception.UOSSException;

public abstract class NativeSQLDAOImpl<T extends GeneralObject> implements NativeSQLDAO<T>{
	
	private String databaseVendor;
	
	@Override
	public abstract Collection<T> searchBySQL(String sql,Class<T> entityClass,Integer beginIndex,Integer fetchSize) throws UOSSException;

	@Override
	public abstract int searchTotalCountBySQL(String sql) throws UOSSException;
	
	
	protected String buildSequenceSQL(String schemaName,String sequenceName){
		String sequenceSQL = null;
		if(Database.DB2.name().equals(this.databaseVendor)){
			sequenceSQL = "select " + schemaName + "." + sequenceName + ".nextval from dual";
		}
		else if(Database.ORACLE.name().equals(this.databaseVendor)){
			sequenceSQL = "select " + schemaName + "." + sequenceName + ".nextval from dual";
		}
		else{
			sequenceSQL = "select " + schemaName + "." + sequenceName + ".nextval from dual";
		}
		return sequenceSQL;
	}

	public String getDatabaseVendor() {
		return databaseVendor;
	}

	public void setDatabaseVendor(String databaseVendor) {
		this.databaseVendor = databaseVendor;
	}
}
